home *** CD-ROM | disk | FTP | other *** search
- { SERIAL.P -- serial interface code }
-
- { Copyright (c) 1987, Ciarcia's Circuit Cellar }
- { All Rights Reserved }
-
-
- {-------------------------------------------------------}
- { Global constants }
-
- CONST
-
- maxtime = 100; { serial timeout }
-
- {-------------------------------------------------------}
- { Global variables }
-
- VAR
- COMerror : INTEGER;
-
- {-------------------------------------------------------}
- { Async card global constants }
-
- CONST
-
- XON = $11;
- XOFF = $13;
-
- DataReady = $01; { receive data ready }
- THRE = $20; { transmit data ready }
-
- {-------------------------------------------------------}
- { Async card global variables }
-
- VAR
-
- comdata : INTEGER; { data for async I/O }
- comien : INTEGER; { interrrupt enable reg }
- comiir : INTEGER; { interrupt ID reg }
- comlcr : INTEGER; { line control reg }
- commcr : INTEGER; { modem control reg }
- comlsr : INTEGER; { line status reg }
- commsr : INTEGER; { modem status reg }
-
- {-------------------------------------------------------}
- { Set up the async card }
- { Rate is in bits/second }
-
- PROCEDURE ComOn(rate : INTEGER);
-
- CONST
- serialmax = 115200.0; { rate -> divisors }
-
- VAR
- dummy : BYTE;
- counts : INTEGER;
-
- BEGIN
-
- {--- set up global variables }
-
- comdata := comport;
- comien := comport + 1;
- comiir := comport + 2;
- comlcr := comport + 3;
- commcr := comport + 4;
- comlsr := comport + 5;
- commsr := comport + 6;
-
- {--- set up port registers }
-
- counts := Trunc(serialmax/rate);
-
- Port[comlcr] := $80; { set DLAB to set rate }
- Port[comdata] := Lo(counts); { set divisor LSB }
- Port[comien] := Hi(counts); { set divisor MSB }
- Port[comlcr] := $13; { no pty 1 stop 8 dat }
-
- dummy := Port[comdata]; { discard pending char }
-
- END;
-
-
- {-------------------------------------------------------}
- { Send a byte to the serial port }
- { If there's an XOFF in the receiver, we wait... }
- { This is not likely, but it has been known to happen }
-
- PROCEDURE SendByte(databyte : BYTE);
-
- BEGIN
-
- COMerror := 0; { can't have error... }
-
- WHILE (Port[comlsr] AND THRE) = 0 DO; { send done? }
-
- WHILE Port[comdata] = XOFF DO; { XOFF pending? }
-
- Port[comdata] := databyte; { send data }
-
- END;
-
-
-